﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;

namespace Tender.Tool
{
    internal static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            //设置未经处理的异常处理模式
            System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            //捕获UI线程异常
            System.Windows.Forms.Application.ThreadException += threadException;
            //捕获多线程异常
            AppDomain.CurrentDomain.UnhandledException += unhandledException;
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
            System.Windows.Forms.Application.Run(new Form1());
        }

        private static void unhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            //处理异常信息
            Exception ex = e.ExceptionObject as Exception;
            if (ex != null)
            {
                System.Windows.MessageBox.Show("程序出现异常：" + ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }

        }

        private static void threadException(object sender, ThreadExceptionEventArgs e)
        {
            //处理异常信息
            Exception ex = e.Exception;
            System.Windows.MessageBox.Show("线程异常：" + ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
        }
    }
}
